/**
 * 
 */
package org.swing.utility.jdbc.handler;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.swing.utility.jdbc.imp.RowProcessor;

/**
 * @author lqnhu
 *
 */
public class ArrayListHandler extends AbstractListHandler<Object[]> {
	/**
	 * The RowProcessor implementation to use when converting rows into
	 * Object[]s.
	 */
	private final RowProcessor convert;

	/**
	 * Creates a new instance of ArrayListHandler using a
	 * <code>BasicRowProcessor</code> for conversions.
	 */
	public ArrayListHandler() {
		this(ArrayHandler.ROW_PROCESSOR);
	}

	/**
	 * Creates a new instance of ArrayListHandler.
	 *
	 * @param convert
	 *            The <code>RowProcessor</code> implementation to use when
	 *            converting rows into Object[]s.
	 */
	public ArrayListHandler(RowProcessor convert) {
		super();
		this.convert = convert;
	}

	/**
	 * Convert row's columns into an <code>Object[]</code>.
	 * 
	 * @param rs
	 *            <code>ResultSet</code> to process.
	 * @return <code>Object[]</code>, never <code>null</code>.
	 *
	 * @throws SQLException
	 *             if a database access error occurs
	 * @see org.apache.commons.dbutils.handlers.AbstractListHandler#handle(ResultSet)
	 */
	protected Object[] handleRow(ResultSet rs) throws SQLException {
		return this.convert.toArray(rs);
	}
}
